﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class RoyalItemRepayBLL : IRoyalItemRepayBLL
    {
        private static readonly IRoyalItemRepayDAL dal = DataAccess.CreateRoyalItemRepays();

        public IList<RoyalItemRepayInfo> ListRoyalItems()
        {
            return dal.ListRoyalItemRepays(new RoyalItemRepayInfo(0));
        }
        public IList<RoyalItemRepayInfo> ListRoyalItems(int Sequence)
        {
            return dal.ListRoyalItemRepays(new RoyalItemRepayInfo(Sequence));
        }
        public void Insert(string RefNo, string Description, string StartDate, string EndDate, string Remarks, int CreatedBy)
        {
            Nullable<DateTime> dtStartDate = StartDate.Length > 0 ? DateTime.Parse(StartDate) : (DateTime?)null;
            Nullable<DateTime> dtEndDate = EndDate.Length > 0 ? DateTime.Parse(EndDate) : (DateTime?)null;
            
            try
            {
                dal.Insert(new RoyalItemRepayInfo(0, RefNo, Description, dtStartDate, dtEndDate, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string RefNo, string Description, string StartDate, string EndDate, string Remarks
            , int UpdatedBy)
        {
            Nullable<DateTime> dtStartDate = StartDate.Length > 0 ? DateTime.Parse(StartDate) : (DateTime?)null;
            Nullable<DateTime> dtEndDate = EndDate.Length > 0 ? DateTime.Parse(EndDate) : (DateTime?)null;

            try
            {
                dal.Update(new RoyalItemRepayInfo(Sequence, RefNo, Description, dtStartDate, dtEndDate, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
